package com.yang.yangCommand;

import com.yang.YangRanks;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CreateRankController implements CommandExecutor {

    private static YangRanks yangRanks;

    public CreateRankController(YangRanks yangRanks) {
        this.yangRanks = yangRanks;
    }

    // 存储团队
    public static final Map<String,List<String>> rankMap = new HashMap<>();

    // 存储加入 | 创建队伍的玩家
    public static final List<String> playerInRanks = new ArrayList<>();


    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        //执行指令
        if(!label.equalsIgnoreCase("createRank")){
            return true;
        }
        if (args.length == 0){
            return true;
        }
        // 判断是否是玩家执行
        if (!(sender instanceof Player)) {
            return true;
        }
        // 创建团队
        // 获取创建团队的玩家名字
        String name = sender.getName();
        // 创建队伍时判断你是否在队伍里
        if (playerInRanks.size() > 0){
            if(playerInRanks.contains(name)){
                return true;
            }
        }
        // 拿到团队名字
        String rankName = args[0];
        // 我们要把团队存起来
        List<String> playerNameList = new ArrayList<>();
        playerNameList.add(name);
        rankMap.put(rankName,playerNameList);
        // 假如你创建了队伍或者存在于队伍时 存储起来
        playerInRanks.add(name);
        sender.sendMessage(ChatColor.GREEN + "创建队伍成功");
        return true;
    }
}
